<?php

namespace App\Admin\Extensions;

use App\Model\User;
use App\Model\UserFreezeLog;
use Encore\Admin\Admin;

class ReportOp extends BaseAction
{
    protected function render()
    {
        $options = '';
        foreach (UserFreezeLog::REASON_TYPE as $k => $type) $options .= '<option value="' . $k . '">' . $type . '</option>';
        $html = '<select id="freeze_type" class="form-control input-sm" style="width:200px; margin:2px 15%">' . $options . '</select>';
        Admin::script($this->script($this->actionUrl, $html));
        $userId = $this->row->reported_user_id;
        $freezebtn = $this->buildButton('fail', '冻结', ['id' => $userId, 'status' => User::STATUS_FREEZE, 'action' => 'status', 'show-html' => 1]);
        $forbid3D = $this->buildButton('fail', '禁言3天', ['id' => $userId, 'status' => User::STATUS_FORBID, 'action' => 'status', 'extra' => 4320]);
        $forbid7D = $this->buildButton('fail', '禁言7天', ['id' => $userId, 'status' => User::STATUS_FORBID, 'action' => 'status', 'extra' => 10080]);
        $forbid14D = $this->buildButton('fail', '禁言14天', ['id' => $userId, 'status' => User::STATUS_FORBID, 'action' => 'status', 'extra' => 20160]);
        $cancelForbidBtn = $this->buildButton('ok', '取消禁言', ['id' => $userId, 'status' => User::STATUS_OK, 'action' => 'status']);
        if (!$userId) return '';
        $user = User::find($userId);
        if (!$user) return '';
        switch ($user->status) {
                //正常
            case User::STATUS_OK:
                $str = [$freezebtn, $forbid3D, $forbid7D, $forbid14D];
                break;
                //冻结
            case User::STATUS_FREEZE:
                $str = [];
                break;
                //禁言
            case User::STATUS_FORBID:
                $str = [$freezebtn, $cancelForbidBtn];
                break;
            default:
                return '';
        }

        return implode("\t", $str);
    }
}
